/* Copyright 1993 Michael B. Johnson
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any non-commercial 
 * purpose and without fee is hereby granted, provided that the 
 * above copyright notice appears in all copies.  Michael B. Johnson
 * makes no representations about the suitability of this
 * software for any purpose.  It is provided "as is" without
 * express or implied warranty.
 *
 * Permission to use, copy, modify or distribute this software
 * and its documentation for any commercial purpose must be
 * confirmed in writing with Michael B. Johnson.  He can be
 * contacted at:
 *              20 Ames St. E15-023G    
 *              Cambridge, MA 02141
 *              (617) 547 0563
 *              
 */


#import "WWTCLClosedCmd.h"
#import "WWTCLVarTrace.h"

@implementation WWTCLClosedCmd

- initWithInterp:newInterp;
{
   [super init];
   interp = newInterp;
   varTraceList = [[List alloc] init];
   closedCmd = NULL;
   originalCmd = NULL;
   return self;
}

- free
{
   // when the var traces get free'ed, they remove themselves from the interp
   //NXLogError("%s %d being free'ed\n", [[self class] name], self);
   [[varTraceList freeObjects] free];
   if (originalCmd) {  free(originalCmd); }
   if (closedCmd) {  free(closedCmd); }

   return [super free];
}

- setOriginalExpression:(const char *)newExpression
{  
   if (originalCmd) { free(originalCmd); }
   originalCmd = NXCopyStringBuffer(newExpression);
   [self setClosedCmd:originalCmd];

   return self;
}

- setClosedCmd:(const char *)newClosedCmd
{
   if (closedCmd) {  free(closedCmd); }
   closedCmd = NXCopyStringBuffer(newClosedCmd);
   return self;
}

- (const char *)cmd  {  return (const char *)closedCmd; }

- addTraceFor:(const char *)argName calling:(Tcl_VarTraceProc *)writeProc using:(ClientData)clientData
{
  WWTCLVarTrace *newTrace = [[WWTCLVarTrace alloc] initWithVarName:argName proc:writeProc datum:clientData delegate:self interp:interp];

 
  [varTraceList addObject:newTrace];
  return self;
}

- (List *)tracedVars
{
    return varTraceList;
}
@end
